package br.urca.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.BiSeriesDAO;
import br.urca.model.BiSeries;

@Transactional
public class JPABiSeriesDAO implements BiSeriesDAO {
	
	private EntityManager manager;
	
	public JPABiSeriesDAO() {
		this(null);
	}
	
	@Inject
	public JPABiSeriesDAO(EntityManager manager) {
		this.manager = manager;
	}
	
	@Override
	public BiSeries getPorId(Short codSerie) {
		return this.manager
				.createQuery(
						"SELECT b FROM BiSeries b where b.codSerie = :codigo",
						BiSeries.class).setParameter("codigo", codSerie)
				.getSingleResult();
	}

	@Override
	public List<BiSeries> getPorDescricao(String nome) {
		return this.manager
				.createQuery(
						"SELECT b FROM BiSeries b WHERE b.nome LIKE '%" + nome + "%'",
						BiSeries.class)
				.getResultList();
	}

}
